package logic

import (
	"errors"
	"hr/dao/mysql"
	"hr/models"
	"hr/pkg/snowflake"
)

func SingUp(p *models.ParamSignUp) (err error) {
	var exist bool
	exist, err = mysql.CheckUserExist(p.Username)
	if err != nil {
		return err
	}
	if exist {
		return errors.New("用户已经存在")
	}
	id := snowflake.GetId()
	u := models.User{
		UserId:   id,
		UserName: p.Username,
		Password: p.Password,
	}
	if err := mysql.InsertUser(&u); err != nil {
		return err
	}
	return nil
}
